package com.jerehedu.myapplication34.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jerehedu.myapplication34.R;
import com.jerehedu.myapplication34.entrty.Prize;

import java.util.List;

/**
 * Created by lenovo on 2016/11/9.
 */
public class PrizeGridAdapter extends BaseAdapter {
    private List<Prize> mData;
    private Context context;

    public PrizeGridAdapter(Context context, List<Prize> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Prize prize=mData.get(position);
        ViewHodler viewHodler=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.grid_view_prize,null,false);
            viewHodler=new ViewHodler();
            viewHodler.img=(ImageView)convertView.findViewById(R.id.imageView);
            viewHodler.name=(TextView)convertView.findViewById(R.id.name);
            viewHodler.score=(TextView)convertView.findViewById(R.id.score);
            convertView.setTag(viewHodler);
        }else{
            viewHodler=(ViewHodler)convertView.getTag();
        }
        Glide.with(context).load(prize.getUrl()).into(viewHodler.img);
        viewHodler.name.setText(prize.getName());
        viewHodler.score.setText("需要积分："+prize.getScore());
        return convertView;
    }


    public class ViewHodler{
        ImageView img;
        TextView name;
        TextView score;
    }
}
